package com.hyt.it.ogt.ks.feign;


import java.io.IOException;

import org.apache.tomcat.jni.FileInfo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import com.hyt.it.ogt.ks.feign.hystrix.FileClientHystrix;



/**
 * 文件服务Feign客户端
 */
@FeignClient(name = "ogtsc-service-file", fallback = FileClientHystrix.class)
public interface FileClient {

	/**
	 * @Description: 上传文件
	 * @param file 文件对象
	 * @return 文件路径
	 */
	@PostMapping(value = "/file/upload/multipartfile",   consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String uploadFile(@RequestPart(value = "file") MultipartFile file) ;

	/**
	 * @Description: 上传文件
	 * @param bytes 文件数据
	 * @param format 文件格式（后缀）
	 * @return String 文件路径
	 */
	@RequestMapping(value = "/file/upload/bytes", method = RequestMethod.POST)
	String uploadFile(@RequestBody byte[] bytes, @RequestParam(value = "format") String format);

	/**
	 * @Description: 把字符串作为指定格式的文件上传
	 * @param content 内容
	 * @param fileExtension 文件扩展名
	 * @return String
	 */
	@RequestMapping(value = "/file/upload/string", method = RequestMethod.POST)
	String uploadFile(@RequestParam(value = "content") String content, @RequestParam(value = "fileExtension") String fileExtension);

	/**
	 * @Description: 上传图片并生成缩略图
	 * @param file 文件对象
	 * @return 文件路径
	 * @throws IOException String
	 */
	@RequestMapping(value = "/file/upload/image/crtthumbimage",
			method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	String uploadImageAndCrtThumbImage(@RequestPart(value = "file") MultipartFile file);

	/**
	 * @Description: 根据图片路径获取缩略图路径（使用uploadImageAndCrtThumbImage方法上传图片）
	 * @param filePath 图片路径
	 * @return String 缩略图路径
	 */
	@RequestMapping(value = "/file/get/thumbimagepath", method = RequestMethod.GET)
	String getThumbImagePath(@RequestParam(value = "filePath") String filePath);

	/**
	 * @Description: 获取文件信息
	 * @param filePath 文件路径
	 * @return FileInfo 文件信息
	 */
	@RequestMapping(value = "/file/query/fileinfo", method = RequestMethod.GET)
	FileInfo queryFileInfo(@RequestParam(value = "filePath") String filePath);

	/**
	 * @Description: 根据文件路径下载文件
	 * @param filePath 文件路径
	 * @return 文件字节数据
	 */
	@RequestMapping(value = "/file/down", method = RequestMethod.GET)
	byte[] downFile(@RequestParam(value = "filePath") String filePath);

	/**
	 * @Description: 根据文件地址删除文件
	 * @param filePath 文件访问地址
	 */
	@RequestMapping(value = "/file/delete", method = RequestMethod.DELETE)
	void deleteFile(@RequestParam(value = "filePath") String filePath);

}
